﻿using System.Text;

namespace Medianamik.Core.DAL.SQL
{
    public class InnerJoin : ISqlQueryPart
    {
        public Column ForeignKeyTableColumn
        {
            get;
            private set;
        }
        public Column PrimaryKeyTableColumn
        {
            get;
            private set;
        }
        public InnerJoin(Column pForeignKeyTableColumn, Column pPrimaryKeyTableColumn)
        {
            PrimaryKeyTableColumn = pPrimaryKeyTableColumn;
            ForeignKeyTableColumn = pForeignKeyTableColumn;
        }

        public StringBuilder ToSQL()
        {
            var join = new StringBuilder(" INNER JOIN ")
                .Append("[" +ForeignKeyTableColumn.Table.Schema + "].[" + ForeignKeyTableColumn.Table.Name + "] ")
                .Append(ForeignKeyTableColumn.Table.Alias)
                .Append(" ON ")
                .Append(ForeignKeyTableColumn.NameWithAlias)
                .Append(" = ")
                .Append(PrimaryKeyTableColumn.NameWithAlias);

            return join;
        }
    }
}
